/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        vector<vector<int>> ret;
        if(root==nullptr)
            return ret;
        queue<Node*> q;
        q.push(root);
        ret.push_back({root->val});

        while(q.size())
        {
            int sz=q.size();
            vector<int> t;
            while(sz--)
            {
                Node* u=q.front();
                q.pop();
                for(auto& e:u->children)
                {
                    q.push(e);
                    t.push_back(e->val);
                }
            }
            if(t.size())
                 ret.push_back(t);
        }
        return ret;
    }
};
